﻿Imports SIRData
Imports SIREntities
Public Class frmLogin

  Private Sub frmLogin_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Try
      Me.Icon = My.Resources.login72x72

      Call CargarValoresGlobalesRegistro()

    Catch ex As Exception
      GC.Collect()
    End Try
  End Sub

  Private Sub btnSalir_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSalir.Click
    Me.Close()
  End Sub

  Private Sub btnAceptar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAceptar.Click
    Try
      Call IngresarAlSistema()

    Catch ex As Exception
      MessageBox.Show(ex.Message, g_sModulo, MessageBoxButtons.OK, MessageBoxIcon.Error)
      txtvLogUsu.SelectAll()
      txtvLogUsu.Focus()
    Finally
      GC.Collect()
    End Try
  End Sub

  Private Sub IngresarAlSistema()
    Dim m_Usuario As New clsUsuario(g_sConnectString)
    Try
      oUsuario = m_Usuario.IngresoSistema(txtvLogUsu.Text.Trim, txtxvPasUsu.Text.Trim)
      MessageBox.Show("Bienvenido " & oUsuario.vNomUsu & "." & vbCrLf & "Ahora puede ingresar al " & g_sModulo, g_sModulo, MessageBoxButtons.OK, MessageBoxIcon.Information)

      Me.Hide()
      MDIMain.Show()

    Catch ex As Exception
      Throw New Exception(ex.Message)
    End Try
  End Sub

  Private Sub txtvLogUsu_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtvLogUsu.KeyDown, btnAceptar.KeyDown, btnSalir.KeyDown, Me.KeyDown
    If e.KeyCode = Keys.Escape Then Me.Close()
  End Sub

  Private Sub txtxvPasUsu_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtxvPasUsu.KeyDown
    Try
      If e.KeyCode = Keys.Escape Then Me.Close()
      If e.KeyCode = Keys.Enter Then IngresarAlSistema()

    Catch ex As Exception
      MessageBox.Show(ex.Message, g_sModulo, MessageBoxButtons.OK, MessageBoxIcon.Error)
      txtvLogUsu.SelectAll()
      txtvLogUsu.Focus()
    Finally
      GC.Collect()
    End Try
  End Sub
End Class